package com.iptv.grape.event.data;

import com.iptv.grape.domain.UserInfo;
import com.iptv.grape.event.EventArgs;
import com.iptv.grape.util.AppConstant;
import com.iptv.grape.util.AppLog;
import com.iptv.grape.util.CommUtil;
import com.starv.dacqapi.DACQAPI;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.Date;

// 上报数据采集
public class DataProc {

    public DataProc(){
        EventBus.getDefault().register(this);
    }



    @Subscribe(threadMode = ThreadMode.BACKGROUND)
    public void onMoonEvent(EventArgs eventArgs){
        if(eventArgs.getEventType().equals(AppConstant.DataAcquisition)) {
            String eName = eventArgs.getEventName();
            switch (eName) {
                case AppConstant.DataLive:
                    dataLiveHelp(eventArgs);
                    break;
                case AppConstant.Vod:
                    vodDataHelp(eventArgs);
                    break;
                case AppConstant.Back:
                    backDataHelp(eventArgs);
                    break;
                case AppConstant.Time:
                    timeDataHelp(eventArgs);
                    break;
            }
        }
    }

    // 直播数据上报
    private void dataLiveHelp(EventArgs eventArgs){
        try {
            LiveData liveData = (LiveData) eventArgs.getEventArgs();
            DACQAPI.getInstance().LiveDataAcq(liveData.getChannelID(),liveData.getChannelName(),
                    liveData.getEnterChannelType(),liveData.getChannelStatus(),liveData.getState(),liveData.getReserve1(),liveData.getReserve2());
            AppLog.getCurLog().out("直播数据上报");
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

    // 点播数据上报
    private void vodDataHelp(EventArgs eventArgs){
        try{
            VodData vodData = (VodData) eventArgs.getEventArgs();
            DACQAPI.getInstance().VodDataAcq(vodData.getColumnID(),vodData.getColumnName(),vodData.getAssetID(),
                    vodData.getFilmName(),vodData.getEpisodes(),vodData.getVodEpisodes(),vodData.getVodTime(),vodData.getVodOperateType(),
                    vodData.getPace(),vodData.getEnterType(),vodData.getFilmType(),vodData.getStartTime(),vodData.getState(),vodData.getProductID(),
                    vodData.getSpID());
            AppLog.getCurLog().out("点播数据上报");
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }
    // 回看数据上报
    private void backDataHelp(EventArgs eventArgs){
        try{
            BackLiveData backLiveData = (BackLiveData) eventArgs.getEventArgs();
            DACQAPI.getInstance().ReplayDataAcq(backLiveData.getChannelID(),backLiveData.getProgramChannelName(),backLiveData.getAsssetID(),
                    backLiveData.getProgramName(),backLiveData.getProgramDuration(),backLiveData.getProgramOperateType(),
                    backLiveData.getPace(),backLiveData.getEnterChannelType(),backLiveData.getStartTime(),backLiveData.getState(),
                    backLiveData.getReserve1(),backLiveData.getReserve2());
            AppLog.getCurLog().out("回看数据上报");
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

    private void timeDataHelp(EventArgs eventArgs){
        try{
            TimeLiveData timeLiveData = (TimeLiveData) eventArgs.getEventArgs();
            DACQAPI.getInstance().TimeShiftDataAcq(timeLiveData.getChannelID(),timeLiveData.getChannelName(),
                    timeLiveData.getProgramOperateType(),timeLiveData.getPace(),timeLiveData.getStartTime(),timeLiveData.getState(),
                    timeLiveData.getReserve1(),timeLiveData.getReserve2());
            AppLog.getCurLog().out("回看数据上报");
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }
}
